home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 February (DVD) / PCWorld_2008-02_DVD.iso / v cisle / PHP / PHP.exe / xampp-win32-1.6.5-installer.exe / phpMyAdmin / scripts / lang-cleanup.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  2007-12-20  |  2.1 KB  |  77 lines

  1. #!/bin/sh
  2. #
  3. # $Id: lang-cleanup.sh 9504 2006-10-06 09:02:46Z nijel $
  4. # vim: expandtab sw=4 ts=4 sts=4:
  5. #
  6. # Script for removing language selection from phpMyAdmin
  7.  
  8. if [ $# -lt 1 ] ; then
  9.     echo "Usage: lang-cleanup.sh type ..."
  10.     echo "Type can be one of:"
  11.     echo "  all-languages - nothing will be done"
  12.     echo "  all-languages-utf-8-only - non utf-8 languages will be deleted"
  13.     echo "  language - keeps utf-8 version of language"
  14.     echo "  language-charset - keeps this exact language"
  15.     echo
  16.     echo "Types can be entered multiple times, all matched languages will be kept"
  17.     exit 1
  18. fi
  19.  
  20. # Construct expressions for find
  21. match=""
  22. for type in "$@" ; do
  23.     case $type in
  24.         all-languages)
  25.             match="$match -and -false"
  26.             ;;
  27.         all-languages-utf-8-only)
  28.             match="$match -and -not -name *-utf-8.inc.php"
  29.             ;;
  30.         *)
  31.             if [ -f lang/$type-utf-8.inc.php ] ; then
  32.                 match="$match -and -not -name $type-utf-8.inc.php"
  33.             elif [ -f lang/$type.inc.php ] ; then
  34.                 match="$match -and -not -name $type.inc.php"
  35.             else
  36.                 echo "ERROR: $type seems to be wrong!"
  37.                 exit 2
  38.             fi
  39.             ;;
  40.     esac
  41. done
  42.  
  43. # Delete unvanted languages
  44. find lang -name \*.inc.php $match -print0 | xargs -0r rm
  45.  
  46. # Cleanup libraries/select_lang.lib.php
  47.  
  48. # Find languages we have
  49. langmatch="$(awk -F, \
  50.     'BEGIN { pr = 1 } ; 
  51.     /^\);/ { pr = 1 } ; 
  52.     {if(!pr) print $2;}; 
  53.     /^\$available_languages/ { pr = 0 };' \
  54.     libraries/select_lang.lib.php \
  55.     | tr -d \' \
  56.     | while read lng ; do if [ -f lang/$lng.inc.php ] ; then echo $lng ; fi ; done \
  57.     | tr '\n' '|' \
  58.     | sed 's/|$//' \
  59.     )"
  60.  
  61. # Prepare working copy
  62. tmp=`mktemp libraries/select_lang.lib.php.XXXX`
  63. cat libraries/select_lang.lib.php > $tmp
  64.  
  65. # Remove languages we don't have
  66. awk -F, \
  67.     'BEGIN { pr = 1 } ; 
  68.     /^\);/ { pr = 1 } ; 
  69.     {if(pr) print $0;}; 
  70.     /'$langmatch'/ {if (!pr) print $0;};
  71.     /^\$available_languages/ { pr = 0 };' \
  72.     $tmp > libraries/select_lang.lib.php
  73.  
  74. # Final cleanup
  75. rm -f $tmp
  76.  
  77.